//
//  FirstViewController.m
//  07-界面通信
//
//  Created by dllo on 16/7/22.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "FirstViewController.h"
#import "SecondViewController.h"
#pragma mark - 签订协议
@interface FirstViewController ()<SecondVCPassValue>

@property (nonatomic, strong) UILabel *label;
@property (nonatomic, strong) UIButton *btn;
@end

@implementation FirstViewController

- (void)viewDidLoad {
    // 关于BaseViewController
    // 是基类的ViewController
    // 在这个ViewController中进行统一的修改
    // 例如: 统一修改背景色, 统一修改坐标系, 等
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
    self.label = [[UILabel alloc] initWithFrame:CGRectMake(50, 0, 200, 50)];
    _label.text = @"sad";
    [self.view addSubview:_label];
    self.btn = [UIButton buttonWithType:UIButtonTypeSystem];
    _btn.frame = CGRectMake(50, 100, 50, 50);
    [_btn setTitle:@"下一页" forState:UIControlStateNormal];
    [self.view addSubview:_btn];
    [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    /**
     *  界面通信
     * 1.属性传值, 从前往后, 将想要传递的值作为后一个界面的属性, 并通过该属性进行一系列操作
     * 将FirstViewController的label.text传递给SecondViewcontroller的textField
     * FirstViewController -> label.text
     * SecondViewcontroller -> str -> 去使用str 
     * 从后往前传 可以, 但是不推荐使用
     * secondViewController -> 取到 textField.text
     *   ↓ pop(获取firstVC)           ↓属性传值
     * firstViewcontroller -> 设置 titleStr -> 去使用
     */
    /* 2.协议传值(delegate)
     * 从后往前传值
     * Second -> First
     * 决定要用代理方式传值
     * 1.决定要在Second声明协议
     * 2.声明delegate @property id <delegate名> delegate;
     * 3.只要可以拿到对象就可以签订协议
     * 4.签订协议
     * 5.实现协议方法
     * 6.但是协议方法并么有执行, 缺少触发时机
     * 触发协议方法, 触发的时候加上判断
     */
    /* 3.关于navgation中控制器的释放
     * navgation中ViewControllers数组, 数组对对象有引用计数+1
     * 当controller入栈时, 则被加入数组中, 引用计数 + 1
     * 只要不出栈, 就不会释放
     * A -> push -> B
     * B -> POP -> A B出栈, 对应释放
     * @class 修饰类 引入头文件, 可以避免掉, 头文件循环引入
     * 只声明我用到这个类, 但是不引入, 什么时候引入, 在.m中import引入
     */
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
}
- (void)clickBtn:(UIButton *)sender {
    SecondViewController *second = [[SecondViewController alloc] init];
    second.str = _label.text;
#pragma Mark - 指定代理人
    second.delegate = self;
    
    [self.navigationController pushViewController:second animated:YES];
}
#pragma mark - 实现协议方法
- (void)passValue:(NSString *)string {
    NSLog(@"%@", string);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
